package cn.yunhe.dao.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import cn.yunhe.dao.CourseDisplaydao;
import cn.yunhe.dao.Coursedao;
import cn.yunhe.entity.Course;
import cn.yunhe.entity.CourseDisplay;

public class CourseDisplayDaoImpl{
	String resource="Config.xml";
	InputStream inputstream;
	SqlSessionFactory ssf;
	public void InsertCourseDisplay(CourseDisplay coursedisplay) throws IOException {
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		CourseDisplaydao coursedisplaydao=sqlsession.getMapper(CourseDisplaydao.class);
		coursedisplaydao.InsertCourseDisplay(coursedisplay);
		sqlsession.close();
		return;
	}
	public CourseDisplay FindCourseDisplayById(String sid) throws IOException{
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		CourseDisplaydao coursedisplaydao=sqlsession.getMapper(CourseDisplaydao.class);
		CourseDisplay courseDisplay=coursedisplaydao.FindCourseDisplayById(sid);
		return courseDisplay;
		
	}
	public void UpdateCourseDisplay(CourseDisplay coursedisplay) throws IOException {
		inputstream=Resources.getResourceAsStream(resource);
		ssf=new SqlSessionFactoryBuilder().build(inputstream);
		SqlSession sqlsession=ssf.openSession();
		CourseDisplaydao coursedisplaydao=sqlsession.getMapper(CourseDisplaydao.class);
		coursedisplaydao.UpdateCourseDisplay(coursedisplay);
		sqlsession.close();
		return;
	}

}
